package common

import (
	"fmt"
	"github.com/jinzhu/gorm"
	"os"
)

var (
	Db *gorm.DB
)

func DbInit() {
	mysqlUrl := os.Getenv("MYSQL_URL")
	println("mysqlUrl: ", mysqlUrl)
	var err error
	// 连接数据库
	Db, err = gorm.Open("mysql", mysqlUrl)
	if err != nil {
		fmt.Print("连接失败！！！！")
		panic(err)
	}
}

func Close() {
	err := Db.Close()
	fmt.Println(err)
}

func UseDb() *gorm.DB {
	return Db
}
